package org.csu.mypetstore.api.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import lombok.Data;
import org.csu.mypetstore.api.pojo.CartItem;

import java.math.BigDecimal;

@Data
@TableName(value = "lineitem")
public class LineItem {
      @MppMultiId
      @TableField(value = "orderID")
      private int orderId;
      @MppMultiId
      @TableField(value = "linenum")
      private int lineNumber;
      @TableField(value = "quantity")
      private int quantity;
      @TableField(value = "itemid")
      private String itemId;
      @TableField(value = "unitprice")
      private BigDecimal unitPrice;
      @TableField(exist=false)
      private Item item;
      @TableField(exist=false)
      private BigDecimal total;

      public LineItem(){

      }

      public LineItem(int i, CartItem cartItem) {
      }

      private void calculateTotal() {
            if (item != null && item.getListPrice() != null) {
                  total = item.getListPrice().multiply(new BigDecimal(quantity));
            } else {
                  total = null;
            }
      }
}
